#include <err.h>
#include <stdio.h>
#include <stdlib.h>

typedef struct
{
    char name[20];
    int force;
    int practice;
    int isofficer;
    int isfrontier;
    int essay;
    int money;
} warrior_t;

int main(int argc, char *argv[])
{
    int n;
    scanf("%d", &n);
    if (n <= 0)
    {
        err(1, "Wrong input\n");
    }

    warrior_t *base;
    base = (warrior_t *)malloc(sizeof(warrior_t) * n);

    char officer, frontier;
    for (int i = 0; i < n; i++)
    {
        scanf("%s%d%d", base[i].name, &base[i].force, &base[i].practice);
        do
        {
            scanf("%c", &officer);
        } while (officer == ' ');
        do
        {
            scanf("%c", &frontier);
        } while (frontier == ' ');
        scanf("%d", &base[i].essay);

        if (officer == 'Y' || officer == 'y')
            base[i].isofficer = 1;
        else if (officer == 'N' || officer == 'n')
            base[i].isofficer = 0;
        else
            err(1, "Wrong input\n");
        if (frontier == 'Y' || frontier == 'y')
            base[i].isfrontier = 1;
        else if (frontier == 'N' || frontier == 'n')
            base[i].isfrontier = 0;
        else
            err(1, "Wrong input\n");

        base[i].money = 0;
    }

    for (int i = 0; i < n; i++)
    {
        if (base[i].force > 80 && base[i].essay >= 1)
            base[i].money += 8000;
        if (base[i].force > 85 && base[i].practice > 80)
            base[i].money += 4000;
        if (base[i].force > 90)
            base[i].money += 2000;
        if (base[i].force > 85 && base[i].isfrontier == 1)
            base[i].money += 1000;
        if (base[i].practice > 80 && base[i].isofficer == 1)
            base[i].money += 850;
    }

    int maxindex = 0;
    int allmoney = base[0].money;
    for (int i = 1; i < n; i++)
    {
        if (base[maxindex].money < base[i].money)
            maxindex = i;
        allmoney += base[i].money;
    }

    printf("%s\n", base[maxindex].name);
    printf("%d\n", base[maxindex].money);
    printf("%d\n", allmoney);

    free(base);
    return 0;
}
